package com.kaijie.admin.modules.common.service;

import com.baidu.aip.ocr.AipOcr;
import org.json.JSONObject;

import java.util.HashMap;

/**
 * 参考：
 * https://blog.csdn.net/jlq_diligence/article/details/87872177?ops_request_misc=&request_id=&biz_id=102&utm_term=%E8%BA%AB%E4%BB%BD%E8%AF%81%E8%AF%86%E5%88%ABJava&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-2-87872177.first_rank_v2_pc_rank_v29&spm=1018.2226.3001.4187
 */
public class Sample {
    // TODO APP_ID/AK/SK
    public static final String APP_ID = "24493007";
    public static final String API_KEY = "cyCGb4BFmV9tSzjItGkoI7SQ";
    public static final String SECRET_KEY = "QNGxdr4GRFYjyf5H8cD44cIDQyrcG6sy";
    
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        // 初始化一个AipOcr
        AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<>();
        options.put("detect_direction", "true");
        options.put("detect_risk", "false");
        // 识别身份证正面（正面图片为本地图片，即：C:\Users\yy150\Pictures\正.jpg）
        JSONObject frontres = client.idcard("D:\\1.jpg", "front", options);
        System.out.println(frontres.toString(2));
        // 识别身份证反面（反面图片为本地图片，即：C:\Users\yy150\Pictures\反.jpg）
        JSONObject backres = client.idcard("D:\\2.jpg", "back", options);
        String ssss=backres.toString(2);
        System.out.println(ssss);
    }

}
